package ${package.Controller};

import com.dbcloud.lxdb.modules.device.model.po.${entity}PO;
import com.dbcloud.lxdb.modules.device.model.dto.${entity}DTO;
import com.dbcloud.lxdb.modules.device.model.query.${entity}PageQuery;
import com.dbcloud.lxdb.modules.device.model.query.${entity}ListQuery;
import com.dbcloud.lxdb.modules.device.model.query.${entity}InfoQuery;
import com.dbcloud.lxdb.modules.device.model.query.${entity}InsertQuery;
import com.dbcloud.lxdb.modules.device.model.query.${entity}UpdateQuery;
import com.dbcloud.lxdb.modules.device.model.vo.${entity}PageVO;
import com.dbcloud.lxdb.modules.device.model.vo.${entity}ListVO;
import com.dbcloud.lxdb.modules.device.model.vo.${entity}InfoVO;
import com.dbcloud.lxdb.common.core.ApiResult;
<#assign myDateType = ["LocalDateTime","LocalDate"]/>
import ${package.Service}.${entity}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.core.bean.BeanUtil;

import javax.annotation.Resource;
import java.util.List;


/**
 * ${table.comment!}控制层
 *
 * @author ${author}
 */
@Api(tags = "${table.comment}文档", value = " ${table.controllerName}")
@Slf4j
@RestController
@RequestMapping("/api/sys/device")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Resource
    private ${table.serviceName} ${table.serviceName?uncap_first};


    @ApiOperation(value = "${table.comment}分页", notes = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/page")
    public ApiResult<Page<${table.entityName}PageVO>> listPage(@Validated @RequestBody ${table.entityName}PageQuery query) {
        // 组装分页参数与查询条件
        Page<${table.entityName}PO> pageQuery = new Page<>(query.getCurrent(), query.getSize());
        ${table.entityName}DTO dto = BeanUtil.copyProperties(query, ${table.entityName}DTO.class);
        // 获取分页数据
        Page<${table.entityName}PageVO> pageVO = ${table.serviceName?uncap_first}.page(pageQuery, dto);
        return ApiResult.success(pageVO);
    }

    @ApiOperation(value = "${table.comment}列表", notes = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/list")
    public ApiResult<List<${table.entityName}ListVO>> list(@Validated @RequestBody ${table.entityName}ListQuery query) {
        // 组装查询条件
        ${table.entityName}DTO dto = BeanUtil.copyProperties(query, ${table.entityName}DTO.class);
        // 获取列表数据
        List<${table.entityName}DTO> listDTO = ${table.serviceName?uncap_first}.list(dto);
        List<${table.entityName}ListVO> listVO = BeanUtil.copyToList(listDTO, ${table.entityName}ListVO.class);
        return ApiResult.success(listVO);
    }

    @ApiOperation(value = "${table.comment}新增", notes = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/insert")
    public ApiResult<Void> insert(@Validated @RequestBody ${table.entityName}InsertQuery insertQuery) {
        ${table.entityName}DTO dto = BeanUtil.copyProperties(insertQuery, ${table.entityName}DTO.class);
        ${table.serviceName?uncap_first}.insert(dto);
        return ApiResult.success();
    }

    @ApiOperation(value = "${table.comment}修改", notes = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/updateById")
    public ApiResult<Void> updateById(@Validated @RequestBody ${table.entityName}UpdateQuery updateQuery) {
        ${table.entityName}DTO dto = BeanUtil.copyProperties(updateQuery, ${table.entityName}DTO.class);
        ${table.serviceName?uncap_first}.updateById(dto);
        return ApiResult.success();
    }

    @ApiOperation(value = "${table.comment}详情", notes = "备注信息")
    @PostMapping("/${table.entityName?uncap_first}/getById")
    public ApiResult<${table.entityName}InfoVO> getById(@Validated @RequestBody ${table.entityName}InfoQuery query) {
        ${table.entityName}DTO detailDTO = ${table.serviceName?uncap_first}.getById(query.getId());
        return ApiResult.success(BeanUtil.copyProperties(detailDTO, ${table.entityName}InfoVO.class));
    }





}
</#if>